package ar.uba.fi.tonyvaliente.tree;

import java.util.NoSuchElementException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import ar.uba.fi.tonyvaliente.tree.BTreeNode.AddResult;

/**
 * Implementación en memoria del árbol.
 * 
 * @author santiago
 *
 */
public class MemoryBTree<K extends Comparable<K>, V> extends BTree<K, V> {

	private static Log log = LogFactory.getLog(MemoryBTree.class);

	public MemoryBTree() throws BTreeException {
		super();
		BReference<K, V> reference = this.createReference();
		reference.setNode(new BTreeNode<K, V>(this));
		this.setRoot(reference);
	}
	
	public MemoryBTree(Integer elementosPorNodo) throws BTreeException {
		super();
		BReference<K, V> reference = this.createReference();
		this.setElementosPorNodo(elementosPorNodo);
		reference.setNode(new BTreeNode<K, V>(this, elementosPorNodo));
		this.setRoot(reference);
	}



	/* (non-Javadoc)
	 * @see ar.uba.fi.datos.tonyvaliente.tree.BTree#createBReference()
	 */
	@Override
	protected BReference<K, V> createReference() {

		BReference<K, V> reference = new MemoryBReference<K, V>();
		return reference;
	}

	/* (non-Javadoc)
	 * @see ar.uba.fi.datos.tonyvaliente.tree.BTree#get(java.lang.Comparable)
	 */
	@Override
	public V get(K key) throws BTreeException, NoSuchElementException {
		return this.getRoot().getNode().get(key);
	}

	@Override
	public void close() {
		// do nothing
	}

}
